﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MVC4App.Repositories.Core;
using MVC4App.Repositories.Core.Security;
using MVC4App.SecurityServiceReference;

namespace MVC4App.Repositories.Implementations.Security
{
    public class PermissionInSiteRepository:RepositoryBase, IPermissionInSiteRepository
    {
        public List<PermissionInSiteDto> GetList(Criterion criterion = null)
        {
            throw new NotImplementedException();
        }

        public List<PermissionInSiteDto> GetQuickSearchPaged(ref int totalPage, int currentPage = 1, string keyword = null)
        {
            throw new NotImplementedException();
        }

        public List<PermissionInSiteDto> GetPaged(ref int totalPage, int currentPage = 1)
        {
            throw new NotImplementedException();
        }

        public PermissionInSiteDto Get(int id)
        {
            throw new NotImplementedException();
        }

        public string Insert(PermissionInSiteDto t)
        {
            throw new NotImplementedException();
        }

        public string Update(PermissionInSiteDto t)
        {
            throw new NotImplementedException();
        }

        public string Delete(int id)
        {
            throw new NotImplementedException();
        }

        public string GrantPermission(List<PermissionInSiteDto> objs, int permissionId)
        {
            var request = new PermissionInSiteRequest().Prepare();
            request.Action = "Create";
            request.PermissionInSites = objs.ToArray();
            request.Criteria = new PermissionInSiteCriteria() { PermissionId = permissionId };
            var response = SecurityServiceClient.SetPermissionInSite(request);
            Correlate(request, response);
            return response.Message;
        }

        public List<PermissionInSiteDto> GetPermissionInSiteByPermissionId(int permissionId)
        {
            var request = new PermissionInSiteRequest().Prepare();
            request.LoadOptions = new[] { "PermissionInSiteByPermission" };
            request.Criteria = new PermissionInSiteCriteria() { PermissionId = permissionId };
            var response = SecurityServiceClient.GetPermissionInSite(request);
            Correlate(request, response);
            return response.PermissionInSites == null ? null : response.PermissionInSites.ToList();
        }
        public List<PermissionInSiteDto> GetPermissionInSiteBySiteId(int siteId)
        {
            var request = new PermissionInSiteRequest().Prepare();
            request.LoadOptions = new[] { "PermissionInSiteBySite" };
            request.Criteria = new PermissionInSiteCriteria() { SiteId = siteId };
            var response = SecurityServiceClient.GetPermissionInSite(request);
            Correlate(request, response);
            return response.PermissionInSites == null ? null : response.PermissionInSites.ToList();
        }
    }
}